<?php

require_once 'Interface.php';

/**
 * Enter description here ...
 * @author griever
 *
 */
class Joob_Session_Behaviour_Namespace implements Joob_Session_Behaviour_Interface {
	
	protected $namespace;
	
	protected $storage;
	
	/**
	 * @return the $namespace
	 */
	public function getNamespace() {
		return $this->namespace;
	}

	/**
	 * @return the $storage
	 */
	public function getStorage() {
		return $this->storage;
	}

	/**
	 * @param field_type $namespace
	 */
	public function setNamespace($namespace) {
		$this->namespace = $namespace;
	}

	/**
	 * @param field_type $storage
	 */
	public function setStorage($storage) {
		$this->storage = $storage;
	}

	public function __construct($storage = null, $namespace = "Joob") {
		if ($storage == null)	{
			require_once 'Joob/Session/Storage/Standard.php';
			$storage = new Joob_Session_Storage_Standard();
		}
		$this->namespace = $namespace;
		$this->storage = $storage;
	}
	
	/**
	 * @see Joob_Session_Namespace_Interface::set()
	 */
	public function set($key, $value) {
		$entry = $this->getEntry ( $key );
		$this->storage->store ( $entry, $value );
	}
	
	/**
	 * @see Joob_Session_Namespace_Interface::get()
	 */
	public function get($key) {
		$entry = $this->getEntry ( $key );
		return $this->storage->retrieve ( $entry );
	}
	
	public function getEntry($key) {
		return $this->namespace . ":" . $key;
	}

}

?>